<ix-modal-header
  [requiredRoles]="requiredRoles"
  [title]="'UPS' | translate"
  [loading]="isFormLoading()"
></ix-modal-header>

<mat-card class="card">
  <mat-card-content>
    <form class="ix-form-container" [formGroup]="form" (submit)="onSubmit()">
      <div class="two-columns">
        <ix-fieldset [title]="helptext.fieldsetGeneral | translate">
          <ix-input
            formControlName="identifier"
            [label]="labels.identifier | translate"
            [tooltip]="tooltips.identifier | translate"
            [required]="true"
          ></ix-input>

          <ix-select
            formControlName="mode"
            [label]="labels.mode | translate"
            [options]="modeOptions$"
            [tooltip]="tooltips.mode | translate"
          ></ix-select>

          @if (isMasterMode) {
            <ix-combobox
              formControlName="driver"
              [label]="labels.driver | translate"
              [tooltip]="tooltips.driver | translate"
              [provider]="providers.driver"
              [required]="true"
            ></ix-combobox>
          } @else {
            <ix-input
              formControlName="remotehost"
              [label]="labels.remotehost | translate"
              [tooltip]="tooltips.remotehost | translate"
              [required]="true"
            ></ix-input>

            <ix-input
              formControlName="remoteport"
              type="number"
              [label]="labels.remoteport | translate"
              [tooltip]="tooltips.remoteport | translate"
              [required]="true"
            ></ix-input>
          }

          <ix-combobox
            formControlName="port"
            [label]="labels.port | translate"
            [tooltip]="tooltips.port | translate"
            [provider]="providers.port"
            [required]="isMasterMode"
            [allowCustomValue]="true"
          ></ix-combobox>
        </ix-fieldset>

        <ix-fieldset [title]="helptext.fieldsetMonitor | translate">
          <ix-input
            formControlName="monuser"
            [label]="labels.monuser | translate"
            [tooltip]="tooltips.monuser | translate"
            [required]="true"
          ></ix-input>

          <ix-input
            formControlName="monpwd"
            type="password"
            [label]="labels.monpwd | translate"
            [tooltip]="tooltips.monpwd | translate"
            [required]="true"
          ></ix-input>

          <ix-textarea
            formControlName="extrausers"
            [label]="labels.extrausers | translate"
            [tooltip]="tooltips.extrausers | translate"
          ></ix-textarea>

          <ix-checkbox
            formControlName="rmonitor"
            [label]="labels.rmonitor | translate"
            [tooltip]="tooltips.rmonitor | translate"
          ></ix-checkbox>
        </ix-fieldset>
      </div>

      <div class="one-column">
        <ix-fieldset [title]="helptext.fieldsetShutdown | translate">
          <ix-select
            formControlName="shutdown"
            [label]="labels.shutdown | translate"
            [options]="shutdownOptions$"
            [tooltip]="tooltips.shutdown | translate"
          ></ix-select>

          <ix-input
            formControlName="shutdowntimer"
            type="number"
            [label]="labels.shutdowntimer | translate"
            [tooltip]="tooltips.shutdowntimer | translate"
          ></ix-input>

          <ix-input
            formControlName="shutdowncmd"
            [label]="labels.shutdowncmd | translate"
            [tooltip]="tooltips.shutdowncmd | translate"
          ></ix-input>

          <ix-checkbox
            formControlName="powerdown"
            [label]="labels.powerdown | translate"
            [tooltip]="tooltips.powerdown | translate"
          ></ix-checkbox>
        </ix-fieldset>
      </div>

      <div class="one-column">
        <ix-fieldset [title]="helptext.fieldsetOther | translate">
          <ix-input
            formControlName="nocommwarntime"
            type="number"
            [label]="labels.nocommwarntime | translate"
            [tooltip]="tooltips.nocommwarntime | translate"
          ></ix-input>

          <ix-input
            formControlName="hostsync"
            type="number"
            [label]="labels.hostsync | translate"
            [tooltip]="tooltips.hostsync | translate"
          ></ix-input>

          <ix-textarea
            formControlName="options"
            [label]="labels.options | translate"
            [tooltip]="tooltips.options | translate"
          ></ix-textarea>

          <ix-textarea
            formControlName="optionsupsd"
            [label]="labels.optionsupsd | translate"
            [tooltip]="tooltips.optionsupsd | translate"
          ></ix-textarea>
        </ix-fieldset>
      </div>

      <ix-form-actions>
        <button
          *ixRequiresRoles="requiredRoles"
          mat-button
          type="submit"
          color="primary"
          ixTest="save"
          [disabled]="form.invalid || isFormLoading()"
        >
          {{ 'Save' | translate }}
        </button>
      </ix-form-actions>
    </form>
  </mat-card-content>
</mat-card>
